package com.liy.framework.common.i18n;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Component
public class I18nValidationMessageConfig extends WebMvcConfigurerAdapter {

    private static Logger logger = LoggerFactory.getLogger(I18nValidationMessageConfig.class);

    @Autowired
    private MessageSource messageSource;


    @Bean
    public LocalValidatorFactoryBean validator() {
        logger.info(">>>数据验证已加入国际化>>>>>>");
        LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
        localValidatorFactoryBean.setValidationMessageSource(this.messageSource);
        return localValidatorFactoryBean;
    }

    public Validator getValidator() {
        return this.validator();
    }
}
